<template>
    <div>
        <Table border :columns="columns" :data="tableData"></Table>
        <Modal v-model="removeModel" width="360">
            <p slot="header" style="color:#f60;">
                <Icon type="information-circled"></Icon>
                <span>删除提示</span>
            </p>
            <div style="text-align:center">
                <p style="font-size:18px;">数据删除后不可恢复，请谨慎操作！</p>
            </div>
            <div slot="footer">
                <Button type="error" @click="remove()" size="large">删除</Button>
                <Button type="info" @click="noRemove()" size="large">取消</Button>
            </div>
        </Modal>
        <!-- 列表弹出 开始 -->
        <Modal
            width="900"
            v-model="partyModel"
            title="添加企业"
            @on-ok="ok"
            @on-cancel="cancel">
            <Form label-position="left" :label-width="72">
                <Row :gutter="15">
                    <i-col span="8">
                        <FormItem label="手机号码：">
                            <Input v-model="mobile" placeholder="请输入手机号码"/>
                        </FormItem>
                    </i-col>
                    <i-col span="8">
                        <Button type="primary" icon="search" @click="searchData">搜索</Button>
                    </i-col>
                </Row>
            </Form>
            <Table
                highlight-row
                max-height="500"
                border
                ref="currentRowTable"
                :columns="partyColumns"
                :data="partyData"
                @on-current-change="partyChange">
            </Table>
            <div style="height: auto;overflow: hidden">
                <Page ref="pages" size="small" :total="itemTotal" show-total style="float: right; margin-top: 20px" @on-change="getList"></Page>
            </div>
        </Modal>
        <!-- 列表弹出 结束 -->
    </div>
</template>

<script>
import ajax from '../../../../libs/axios.js'
export default {
    props: {
        tableData: Array,
        access: Object
    },
    data () {
        return {
            removeModel:false,      // 删除弹窗
            partyModel: false,      // 添加企业弹窗
            id: '',
            partySection: {},
            itemTotal: 0,           // table条数
            mobile: '',             // 手机号码
            partyData: [],          // 数据集合
            data: [],
            partyId:'',             // 企业id
            columns: [
                {
                    title: '序号',
                    type: 'index',
                    width: 80,
                    align: 'center'
                },
                {
                    title: '用户名',
                    width: 140,
                    align: 'center',
                    key: 'loginName'
                },
                {
                    title: '手机号码',
                    align: 'center',
                    key: 'mobile',
                    width: 140,
                },
                {
                    title: '真实姓名',
                    width: 140,
                    align: 'center',
                    key: 'realName'
                },
                {
                    title: '身份证号码',
                    align: 'center',
                    key: 'cardNum',
                    width:180,
                },
                {
                    title: '来源',
                    align: 'center',
                    key: 'dataSource',
                    width: 80,
                    render: (h, params) => {
                        if (params.row.dataSource === 1) {
                            return h('span', '前端')
                        }  else if(params.row.dataSource === 2) {
                            return h('span', '后台')
                        }else{
                            return h('span', '其他')
                        }
                    }
                },
                {
                    title: '状态',
                    align: 'center',
                    key: 'status',
                    width: 100,
                    render: (h, params) => {
                        if (params.row.status === 1) {
                            return h('span', '待审核')
                        }  else if(params.row.status === 2) {
                            return h('span', '审核成功')
                        }else if(params.row.status === 3) {
                            return h('span', '审核失败')
                        }else{
                            return h('span', '其他')
                        }
                    }
                },
                {
                    title: '用户角色',
                    align: 'center',
                    key: 'userRoles',
                    width: 100,
                    render: (h, params) => {
                        if (params.row.userRoles === 1) {
                            return h('span', '法人')
                        }  else if(params.row.userRoles === 2) {
                            return h('span', '签约代理人')
                        }  else if(params.row.userRoles === 3) {
                            return h('span', '销售经理')
                        }  else if(params.row.userRoles === 4) {
                            return h('span', '非企业员工')
                        }  else{
                            return h('span', '其他')
                        }
                    }
                },
                {
                    title: '发车权限',
                    align: 'center',
                    key: 'isCar',
                    width: 100,
                    render: (h, params) => {
                        if (params.row.isCar === 0) {
                            return h('span', '禁止')
                        }  else if(params.row.isCar === 1) {
                            return h('span', '允许')
                        }else{
                            return h('span', '其他')
                        }
                    }
                },
                {
                    title: '创建时间',
                    align: 'center',
                    key: 'crtTime',
                    width:180,
                },
                {
                    title: '操作',
                    key: 'action',
                    width: 210,
                    align: 'center',
                    fixed: 'right',
                    render: (h, params) => {
                        return h('div', [
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'primary',
                                        size: 'small'

                                    },
                                    style: {
                                        marginRight: '5px',
                                        display: this.access.edit === true ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                            this.infoData(params.row.id)
                                        }
                                    }
                                },
                                '详情'
                            ),
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px',
                                        display:params.row.dataSource != 1 ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                            this.goRemove(params.index, params.row.id)
                                        }
                                    }
                                },
                                '删除'
                            ),
                            // h(
                            //     'Button',
                            //     {
                            //         props: {
                            //             type: 'info',
                            //             size: 'small'
                            //         },
                            //         style: {
                            //             marginRight:'5px',
                            //             display: this.access.func === true && params.row.status != 2 ? 'inline-block' : 'none'
                            //         },
                            //         on: {
                            //             click: () => {
                            //                  this.auditData(params.row.id)
                            //             }
                            //         }
                            //     },
                            //     '审核'
                            // ),
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'success',
                                        size: 'small'
                                    },
                                    style: {
                                        display: this.access.func === true ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                             this.editData(params.row.id)
                                        }
                                    }
                                },
                                '修改'
                            )
                            // h(
                            //     'Button',
                            //     {
                            //         props: {
                            //             type: 'primary',
                            //             size: 'small'
                            //         },
                            //         style: {
                            //             marginRight: '5px',
                            //             display: params.row.status === 2 ? 'inline-block' : 'none'
                            //         },
                            //         on: {
                            //             click: () => {
                            //                 this.id = params.row.id
                            //                 this.partyModel = true
                            //                 this.personalInfo(params.row.id);
                            //             }
                            //         }
                            //     },
                            //     '添加企业'
                            // )
                        ])
                    }
                }
            ],
            partyColumns: [
                {
                    title: '序号',
                    type: 'index',
                    width: 60,
                    align: 'center'
                },{
                    title: '用户名',
                    align: 'center',
                    key: 'name'
                },
                {
                    title: '手机号码',
                    align: 'center',
                    key: 'legalPhone'
                },
                {
                    title: '法人名称',
                    align: 'center',
                    key: 'legalPerson'
                }
            ],
        }
    },
    created () {
        this.init()
    },
    activated () {
        this.init()
    },
    methods: {
        // 初始化数据
        init () {
            this.partyData = [];
        },
        // 初始化获取详情信息
        personalInfo(id) {
            var _that = this;
            var url = 'adminlogin/getCjUserById';
            var data = {
                id: id
            };
            ajax.formRes(url, data).then(function (res) {
                if (200 == res.code) {
                    _that.partyId = res.data.partyId;
                    _that.selectCjPartyByStatus (res.data.partyId,id,1)
                } else {
                    _that.$Message.success('数据原因，请联系管理员。');
                }
            }).catch(function (err) {
                console.log('有错误信息');
            });
        },
        // 搜索
        searchData(){
            this.selectCjPartyByStatus(this.partyId,this.id,1)
        },
        // 获取企业设置数据
        selectCjPartyByStatus (partyId,id,page) {
            this.partyData = [];
            this.id = id;
            //获取审核通过的所有公司
            let _that = this;
            let url = 'adminlogin/selectCjPartyByStatus'
            let data = {
                statusValue:2,
                mobile: this.mobile,
                pageSize: 10,
                pageNum: page,
                partyId:partyId
            }
            ajax.formRes(url, data).then(res => {
                _that.partyData = res.data;
                _that.itemTotal = res.count;
            }).catch(err => {
                console.log('有错误信息')
            })
        },
        // 审核操作
        auditData (id) {
            let argu = {
                id: id
            }
            this.$router.push({
                name: 'auditPersonInfo',
                params: argu
            })
        },
        // 修改操作
        editData (id) {
            let argu = {
                id: id
            }
            this.$router.push({
                name: 'editpersonal',
                params: argu
            })
        },
        // 详情
        infoData (id) {
            let argu = {
                id: id
            }
            this.$router.push({
                name: 'personInfo',
                params: argu

            })
        },
        // 删除
        goRemove (index, id) {
            this.modal = true
            this.id = id
            this.index = index
            this.removeModel = true
        },
        // 删除确定操作
        remove () {
            let url = 'adminlogin/deleteCjUser'
            let data = {
                id: this.id
            }
            ajax.formRes(url, data).then(res => {
                if (res.data > 0) {
                    this.tableData.splice(this.index, 1)
                    this.removeModel = false
                }
            }).catch(err => {
                console.log('有错误信息')
            })
        },
        // 删除取消操作
        noRemove () {
            this.removeModel = false
        },
        // 取消操作
        cancel () {
            this.partySection = {}
            this.partyModel = false
        },
        // 添加企业操作
        ok () {
            this.partyId = this.partySection.id
            //更新用户的企业信息
            let that = this
            let data = {
                id:this.id,
                partyId:this.partySection.id
            }
            let url = 'adminlogin/updateCjUser'
            ajax.formRes(url, data).then(res => {
                // success
                that.$Message.success('数据设置成功,页面正在跳转')
                let argu = {}
                that.$router.push({
                    name: 'personalindex',
                    params: argu
                })
            }).catch(err => {
                console.log('有错误信息')
            })

        },
        // 拖拽
        partyChange (section) {
            this.partySection = section
        },
        getList (page) {}
    },
}
</script>
